/**
 * LobsterHISClient客户端成功登录后的主界面服务
 */
class tshomeController {
    public data = {
        dbConn: TSLobsterAPI.Program.GetDbConn(),
        dbConnBoot: TSLobsterAPI.Program.GetDbConn("LobsterBoot"),
        WorkId: 1
    }

    public service: tshomeService;
    public dao: tshomeDao;

    constructor() {
        this.data.WorkId = TSLobsterAPI.Program.GetWorkId();

        this.service = new tshomeService(this.data.WorkId);
        this.dao = new tshomeDao(this.data.WorkId);

    }
    /**采用用户代码登录 */
    loginbyusercode() {
        var usercode = TSLobsterAPI.Program.RequestQuery('usercode', '');
        var baseuser = this.dao.getuser(usercode);
        // TSLobsterAPI.Utils.TrackLog("baseuser",baseuser);
        var defaultdept = this.dao.getdefaultdept(baseuser.EmpID) || {};
        // TSLobsterAPI.Utils.TrackLog("defaultdept",defaultdept);
        var baseemp = this.dao.getbaseemployee(baseuser.EmpID);
        // TSLobsterAPI.Utils.TrackLog("baseemp",baseemp);
        var basework = this.dao.getbaseworker(baseuser.WorkId);
        // TSLobsterAPI.Utils.TrackLog("basework",basework);
        var modulelist = this.dao.getmodulelist(baseuser.UserID, baseuser.IsAdmin);
        // TSLobsterAPI.Utils.TrackLog("modulelist",modulelist);
        var menulist = this.dao.getmenulist(baseuser.UserID, baseuser.IsAdmin);
        // TSLobsterAPI.Utils.TrackLog("menulist",menulist);
        var havedept = this.dao.gethavedeptlist(baseuser.EmpID);
        // TSLobsterAPI.Utils.TrackLog("havedept",havedept);
        var right = {
            UserId: baseuser.UserID,
            EmpId: baseuser.EmpID,
            WorkId: baseuser.WorkId,
            IsAdmin: baseuser.IsAdmin,
            DeptId: defaultdept.DeptId || 0,
            DeptName: defaultdept.Name || '',
            EmpName: baseemp.Name || '',
            WorkName: basework.WorkName || ''
        }

        return { EmpName: right.EmpName, DeptName: right.DeptName, WorkName: right.WorkName, ModuleList: modulelist, MenuList: menulist, HaveDept: havedept, right: right };
    }
    /**获取报表配置 */
    getReportBasicData() {
        var dtreport = this.dao.getReportBasicData();
        return { dtreport: dtreport };
    }

    /**获取未读消息 */
    getNotReadMessages() {
        var empid = TSLobsterAPI.Program.RequestQuery('empid', '');
        var msglist = this.dao.getNotReadMessages(empid);
        return { msglist: msglist };
    }
    /**设置消息已读 */
    setMessageRead() {
        var ids = TSLobsterAPI.Program.RequestQuery('ids', '');
        if (ids != '') {
            this.dao.setMessageRead(ids);
        }
    }

    /**获取Web菜单，显示在工作台 */
    getWebAllMenus() {
        var ssouserid = TSLobsterAPI.Program.GetSSOUserId();
        var moduleList = this.dao.geAllBaseModule(ssouserid);
        moduleList.forEach(m_item => {
            var classList = this.dao.getAllBaseClass(ssouserid, m_item.ModuleId, -1);
            var menuList = this.dao.getAllBaseMenu(ssouserid, m_item.ModuleId, -1);//没有分类，直接菜单
            m_item.classList = classList;
            m_item.menuList = menuList;
            classList.forEach(item => {
                var menuList2 = this.dao.getAllBaseMenu(ssouserid, m_item.ModuleId, item.MenuId);
                item.menuList = menuList2;
            })
        })

        return { moduleList: moduleList };
    }
}